import java.io.*;
import java.net.*;

public class Client {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost", 8888);

            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

            String inputLine;
            System.out.print("输入您的信息 (输入 'exit' 退出程序): ");
            while (!(inputLine = reader.readLine()).equalsIgnoreCase("exit")) {
                out.println(inputLine);
                System.out.println("Server response: " + in.readLine());
                System.out.print("输入您的信息给服务端(输入 'exit' 退出程序): ");
            }

            reader.close();
            in.close();
            out.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
